package cn.lqz.bucttrain.controller;

import cn.lqz.bucttrain.annotations.PageQueryAutoFill;
import cn.lqz.bucttrain.pojo.dto.UserPageQueryDTO;
import cn.lqz.bucttrain.pojo.entity.User;
import cn.lqz.bucttrain.pojo.vo.OrderVO;
import cn.lqz.bucttrain.pojo.vo.PageResultVO;
import cn.lqz.bucttrain.pojo.vo.ResponseVO;
import cn.lqz.bucttrain.service.UserService;
import cn.lqz.bucttrain.utils.ResponseUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户请求
 */
@RestController
@RequestMapping("/user")
@Validated
public class UserController {
    @Resource
    private UserService userService;

    /**
     *  查询
     * @param userPageQueryDTO
     * @return
     */
    @PostMapping("/loadUserList")
    @PageQueryAutoFill
    public ResponseVO<PageResultVO> loadUserList(UserPageQueryDTO userPageQueryDTO){
        return ResponseUtils.success(userService.loadUserList(userPageQueryDTO));
    }

    /**
     * 新增或修改
     * @param user
     * @return
     */
    @PostMapping("/addOrUpdateUser")
    public ResponseVO addOrUpdateUser(@Valid User user){
        userService.addOrUpdateUser(user);
        return ResponseUtils.success();
    }

    /**
     * 删除
     * @param userId
     * @return
     */
    @PostMapping("/deleteUser")
    public ResponseVO deleteUser(@NotNull Long userId){
        userService.deleteUser(userId);
        return ResponseUtils.success();
    }
    /**
     * 导出用户excel表
     * @param userList
     * @param response
     */
    @PostMapping("/exportUserExcel")
    public void exportOrderExcel(@RequestBody List<User> userList, HttpServletResponse response){
        userService.exportUserExcel(userList,response);
    }
}
